package com.sean.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sean.service.IEmployeeFacade;

@Controller
public class EmployeeController {
	private Logger logger = Logger.getLogger(EmployeeController.class);

	@Autowired
	private IEmployeeFacade employeeFacade;

	@RequestMapping("/employee/find.do")
	public ModelAndView findEmployee(HttpServletRequest resq,
			HttpServletResponse resp) {
		logger.error("Go to find.do");
		String roleString = resq.getParameter("roles");
		List list = null;
		if (roleString == null || roleString.equals("")) {
			list = employeeFacade.findEmployeeByRoles(null);
		} else {
			list = employeeFacade.findEmployeeByRoles(roleString.split(","));
		}
		//logger.info("Select size " + list.size());
		ModelMap modelMap = new ModelMap();
		modelMap.addAttribute("employeeList", list);
		ModelAndView modelAndView = new ModelAndView("employee/list", modelMap);
		return modelAndView;
	}
}
